<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <add />
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('id')" prop="id" label="id" />
        <el-table-column v-if="columns.visible('name')" prop="name" label="规格名称" />
        <el-table-column v-if="columns.visible('value')" prop="value" label="规格值" >
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.value">
              {{ item.value }} : {{ item.detail.join(',')}}
            </div>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('create_time')" prop="create_time" label="创建时间">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.create_time) }}</span>
          </template>
        </el-table-column>
        <el-table-column v-permission="['admin','yxStoreProductRule:edit','yxStoreProductRule:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudProductAttr from '@/api/product/specifications'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'
import MaterialList from "@/components/material/index.vue"
import add from './form.vue'

// crud交由presenter持有
const defaultCrud = CRUD({ title: '商品规格', url: 'admin/get-product-specifications-list', sort: 'id,desc', crudMethod: { ...crudProductAttr }})
const defaultForm = { id: null, name: null, value: null, create_time: null }
export default {
  name: 'ProductSpecifications',
  components: { pagination, crudOperation, rrOperation, udOperation ,MaterialList,add},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  data() {
    return {
        //newData: null,
        permission: {
          add: ['admin', 'rule:add'],
          edit: ['admin', 'rule:edit'],
          del: ['admin', 'rule:del']
        }
      }
  },

  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.afterRefresh]() {
      return true
    },

    [CRUD.HOOK.afterToCU](crud, form) {
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
